﻿// Decompiled with JetBrains decompiler
// Type: Bannerlord.BUTR.Shared.Extensions.DictionaryExtensions
// Assembly: MCMv5, Version=5.10.2.0, Culture=neutral, PublicKeyToken=null
// MVID: 7AB326B9-B2B4-41C2-9177-68E944071101
// Assembly location: D:\steam\steamapps\workshop\content\261550\2859238197\bin\Win64_Shipping_Client\MCMv5.dll

using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;

#nullable enable
namespace Bannerlord.BUTR.Shared.Extensions
{
  [ExcludeFromCodeCoverage]
  [DebuggerNonUserCode]
  internal static class DictionaryExtensions
  {
    public static void Deconstruct<TKey, TValue>(
      this KeyValuePair<TKey, TValue> tuple,
      out TKey key,
      out TValue value)
    {
      key = tuple.Key;
      value = tuple.Value;
    }

    public static void AddRangeCautiously<TKey, TValue>(
      this Dictionary<TKey, TValue> destinationDict,
      Dictionary<TKey, TValue> otherDict,
      bool overrideDuplicates = false)
    {
      if (destinationDict == null)
        destinationDict = new Dictionary<TKey, TValue>();
      if (otherDict == null)
        otherDict = new Dictionary<TKey, TValue>();
      foreach (KeyValuePair<TKey, TValue> keyValuePair in otherDict)
      {
        if (!destinationDict.ContainsKey(keyValuePair.Key))
          destinationDict.Add(keyValuePair.Key, keyValuePair.Value);
        else if (overrideDuplicates)
          destinationDict[keyValuePair.Key] = keyValuePair.Value;
      }
    }

    public static void AddRange<TKey, TValue>(
      this Dictionary<TKey, TValue> destinationDict,
      Dictionary<TKey, TValue> otherDict)
    {
      foreach (KeyValuePair<TKey, TValue> keyValuePair in otherDict)
        destinationDict.Add(keyValuePair.Key, keyValuePair.Value);
    }
  }
}
